//初始化数据
import api from "../../../system/api/api_kind";
import httpclient from 'httpclient';
const state = {
    departList: [],//科室路由集合
    depart: [],//当前科室路由对象
    routeFuncsList: [],//index功能路由集合
    routeData: [],//功能路由对应的data
    systemRoute:{},//当前系统功能的路由
    systemNames:[],//系统列表
};
const mutations = {
    /**
     * 当前系统路由提交
     * @param state state状态
     */
    setSystemRoute(state){
        let menus = {};
        let navs = [];
        let childs = [];
        httpclient.sendPost(api.LOGIN.AUTH_MENU).done((res) => {
            if (res.code === 1) {
                res.data.list.forEach(function (parent) {
                    if (parent.parent === null) {
                        res.data.list.forEach(function (nav) {
                            if (parent.id === nav.parent) {
                                res.data.list.forEach(function (child) {
                                    if (nav.id === child.parent) {
                                        childs.push({
                                            "childRouteName": child.code,
                                            "path": child.pathname,
                                            "childColumnName": child.name,
                                            "childRoutePath": child.url,
                                            "parentId":child.parent
                                        });
                                    }
                                });
                                navs.push({
                                    "navColumnName": nav.name,
                                    "navRouteName": nav.code,
                                    "path": nav.pathname,
                                    "childs": childs,
                                    "navRoutePath": nav.url,
                                    "parentId":nav.parent,
                                    "id":nav.id
                                });
                                childs = [];
                            }
                        });
                        menus[parent.id]={
                            "parentColumnName": parent.name,
                            "parentRouteName": parent.code,
                            "path": parent.pathname,
                            "childs": navs,
                            "id":parent.id
                        };
                        navs =[];
                    }
                });
                state.systemRoute = menus;
            } else {
                ELEMENT.Message.warning({message: res.errorMsg});
            }
        }).fail((data) => {
            ELEMENT.Message.error({message: data.errorMsg});
        });
    },

    setDepartList(state, data) {
        state.departList = data;
    },
    setDepart(state, data) {
        state.depart = data;
    },
    setRouteFuncs(state, data) {
        state.routeFuncsList = data;
    },
    setRouteData(state, data) {
        state.routeData = data;
    },
};
//getter 抛出去的数据
const getters = {
    departList: state => state.departList,
    depart: state => state.depart,
    routeFuncsList: state => state.routeFuncsList,
    routeData: state => state.routeData,
    systemRoute:state=>state.systemRoute,
    systemNames:state=>state.systemNames,
};
export default {
    state,
    mutations,
    getters,
};
